package jjn.daily;

import java.util.Arrays;

/**
 * @author Jiang Jining
 * @since 2023-07-08 22:13
 */
public class LeetCode167 {
    public int[] twoSum(int[] numbers, int target) {
        int left = 0, right = numbers.length - 1;
        while (left < right) {
            if (numbers[left] + numbers[right] == target) {
                return new int[]{left + 1, right + 1};
            } else if (numbers[left] + numbers[right] < target) {
                left++;
            } else {
                right--;
            }
        }
        return new int[0];
    }
    
    public static void main(String[] args) {
        int[] numbers = new int[]{2, 7, 11, 15};
        int target = 9;
        int[] twoSum = new LeetCode167().twoSum(numbers, target);
        System.out.println("twoSum = " + Arrays.toString(twoSum));
    }
}
